package com.li.sssp.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.li.sssp.entity.Actor;
import com.li.sssp.entity.Module;
import com.li.sssp.entity.Role;

/**
 * RoleRepository
 * @author guazi
 * @date 2017/03/13
 * @version V1.0
 */
public interface RoleRepository extends JpaRepository<Role, Integer> {

	/**
	 * 获取所有
	 */
	List<Role> findAll();

	/**
	 * 根据actor和page获取（分页）
	 * @param actor
	 * @param page
	 * @return
	 */
	Page<Role> findByActor(Actor actor,Pageable page);
	
	/**
	 * 根据actor获取（无分页）
	 * @param actor
	 * @return
	 */
	List<Role> findByActor(Actor actor);
	
//	@Query("from Role r where r.actor=?1 and r.module=?2")
//	List<Role> findByModuleAndActor(Actor actor, Module module);
	
	/**
	 * 根据query查找
	 * @param actor
	 * @param module
	 * @param c
	 * @return List<Role>
	 */
	@Query("from Role r where r.actor=?1 and r.module=?2 and c=?3")
	List<Role> findByModuleAndActor(Actor actor, Module module,String c);
	

	/**
	 * 根据actor进行删除
	 * @param actor
	 * @return
	 */
	@Modifying
	@Query("delete from Role r where r.actor=?1")
	Integer DelAllByActor(Actor actor);
	
}
